<!--
 * @Author: your name
 * @Date: 2021-11-13 16:29:01
 * @LastEditTime: 2021-11-13 16:34:37
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue-note\day03\04.监听属性的完整写法.html
-->
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>04.监听属性的完整写法</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <p>{{user.name}}</p>
    </div>
    <script>
      const vm = new Vue({
        el: "#app",
        data: {
          msg: "hello",
          user: {
            name: "jack",
            age: 20,
          },
        },
        watch: {
          // 这是完整写法
          user: {
            // user中的数据只要一变化，就会执行hander函数
            handler(newValue, oldValue) {
              console.log(newValue, oldValue);
            },

            // 表示深度监视，监视复杂数据类型的时候一定要加上这个属性
            deep: true,

            // 表示一开始渲染就要执行hander函数中的代码
            immediate: true,
          },
        },
      });
    </script>
  </body>
</html>
